rm(list = ls())

library(kableExtra)
library(tidyverse)

## Load MP data

dat <- readRDS('data/mp_data.rds')  %>%
  filter(vote_abstain_no_show == 0) %>%
  filter(elecper != 8)

##

experience_covars <- c('nsdap_member', 
                       'syn_in_gem_bin', 
                       'syn_in_loc_33_39',
                       'veteran_ww1',
                       'veteran_ww2', 
                       'capture_ww2',
                       'soviet_capture',
                       'exile_repressed_combined', 
                       'resistance_member',
                       'rel_cath')

experience_covars_labels <- c('NSDAP member', 
                              'Synagogue in hometown',
                              'Synagogue in 1933--1939 location',
                              'WW1 Veteran', 
                              'WW2 Veteran',
                              'WW2 POW',
                              'Soviet POW',
                              'Repressed or in exile during WW2', 
                              'Resistance against Nazis', 
                              'Catholic')

## Get covar means 

summary_all <- dat %>%
  distinct(mp_id, .keep_all = T) %>%
  group_by(party_fe) %>%
  summarise_at(experience_covars, mean, na.rm = T) %>%
  t() %>%
  .[-1,] %>% 
  as_data_frame() %>%
  mutate(variable = experience_covars_labels) %>%
  mutate_at(1:3, ~ round(as.numeric(.)*100, 4)) %>%
  dplyr::select(variable, everything()) 

# To Tex Table 

tab_tex <- summary_all %>%
  kableExtra::kable(., 
                    format = 'latex', 
                    booktabs = T,
                    linesep = "",
                    col.names = c('Variable', 'CDU/CSU', 'FDP', 'SPD'),
                    label = 'sumstat_covariates',
                    caption = 'Overview of biography covariates',
                    digits = 2) %>%
  add_footnote("The Table shows the share of MPs with a given characteristic by party (in %).", 
               notation = "none", 
               threeparttable = F) %>%
  kable_styling(latex_options = c("HOLD_position"), 
                position = "center",
                full_width = F,
                font_size = 12) 

tab_tex



